var faspreadonlyColor = 'background:#DFE8F6;';
/**
 * 提示 isSuccessNotHint 成功后不提示(默认是false)
 */
function alertpand(str, isSuccessNotHint) {
	var responseArray = Ext.util.JSON.decode(str);
	if (responseArray.success == true || responseArray.success == 'true') {
		// alert(isSuccessNotHint);
		if (!isSuccessNotHint || isSuccessNotHint == false) {
			Ext.MessageBox.show({
						title : '操作成功',
						msg : responseArray.info,
						buttons : Ext.Msg.OK,
						icon : Ext.MessageBox.INFO
					});
		}
		return true;
	} else {
		Ext.MessageBox.show({
					title : '操作失败',
					msg : responseArray.info,
					buttons : Ext.Msg.OK,
					icon : Ext.MessageBox.ERROR

				});

		return false;
	}

}
function addFrameCenterTab(id,taburl,title){
	var tabItem = frame_center.getItem(id);
				if (tabItem == null) {
					tabItem = frame_center.add(new Ext.Panel({
							id :id,
							title :title,
							closable : true,
							autoHeight : true,
							autoScroll : true,
							layoutOnTabChange : true,
							layout : 'fit',
							border : false,
							autoLoad : {url : taburl,scripts : true,callback : this.initSearch,scope : this,discardUrl : true,nocache : false,text : "页面加载中,请稍候……",timeout : 9000}
							}));
				
				}
				if(tabItem)
				tabItem.show();
}


function addStoreBaseParams(field,name,store){
 var value=field.getValue();
 if(value!='')
	store.baseParams[name] = value;
else
	delete store.baseParams[name];
 
}

function formatArrayStr(array) {
	return function(v) {
		return array[v]
	}
}

function formatStratmark(value) {
	return value == 1 ? "启用" : "未启用";
}
function money1(v) {
	var v1 = Ext.util.Format.usMoney(v);
	v1 = v1.replace('$', '');
	return '<span style="color:blue;">' + v1 + '</span>';
}
function closeAllTab() {
	frame_center.items.each(function(item) {
				if (item.closable)
					frame_center.remove(item);
			})

}
function showreload(myPanel, reloadFunction) {
	if (myPanel && reloadFunction)
		myPanel.on("show", reloadFunction)

}
function storeSum(store, sumcolnames, sumtextcolname, sumtext) {
	store.on('load', function() {
				var count = store.getCount();
				var ret = [];

				ret[sumtextcolname] = sumtext ? sumtext : " 合计:";
				for (var j = 0; j < sumcolnames.length; j++) {
					ret[sumcolnames[j]] = 0;
				}
				if (count > 0) {
					for (var i = 0; i < count; i++) {
						for (var j = 0; j < sumcolnames.length; j++) {

							ret[sumcolnames[j]] += store.getAt(i)
									.get(sumcolnames[j]);
						}
					}
				}
				var p = new store.recordType(ret);
				store.add(p);
			});

}

function destroyResize(mainpanel, destroyObjs) {
	var myPanel = frame_center.getActiveTab();
	var myresize = function(frame) {
		myPanel.on("show", function() {
					mainpanel.syncSize()
				});
		mainpanel.setSize(frame_center.getInnerWidth() - 2, frame_center
						.getInnerHeight());
	}
	myPanel.on("beforedestroy", function() {
				frame_center.un("resize", myresize);
				if (destroyObjs) {
					for (var i = 0; i < destroyObjs.length; i++) {
						if (destroyObjs[i]!=null) {
							//alert(destroyObjs[i]);
							destroyObjs[i].destroy();
							//delete destroyObjs[i];
						}
					}
				}
			});
	frame_center.on("resize", myresize);

}

function evalArrayJS(tabJsArray, scope, callback) {
	var num = tabJsArray.length;
	var jsStr = [];
	var currentIndex = 0;

	for (var i = 0; i < num; i++) {
		Ext.Ajax.request({
					method : 'GET',// 为了不丢失js文件内容，所以要选择post的方式加载js文件
					url : tabJsArray[i],
					scope : scope,
					success : function(response) {
						jsStr.push(response.responseText);// 把每次加载的内容都存入jsStr中
						if (currentIndex == num - 1) {// 如果当前索引号为最后一个时开始创建应用的实例
							try {
								eval(jsStr.join("\n"));
							} catch (e) {
															

								alert(e);
							}
							Ext.callback(this.main, this);
							Ext.callback(callback, this);
						}
						currentIndex++;
					}
				});
	}

}

function errAlert(msg) {
	Ext.MessageBox.show({
				title : '操作失败',
				msg : msg,
				buttons : Ext.Msg.OK,
				icon : Ext.MessageBox.ERROR

			});
}
function deleteData(url, sendParam, store, confirmMsg, isNotAlert, backFunction) {
	var deleteAjax = function() {

		Ext.lib.Ajax.request('POST', url, {
					success : function(request) {
						if (isNotAlert)
							return;
						var message = request.responseText;
						if (alertpand(message)) {
							if (store) {
								store.reload();
							}
							Ext.callback(backFunction)
						}
					},
					failure : function() {
						Ext.Msg.alert("错误", "与后台联系的时候出现了问题");
					}
				}, sendParam);
	}
	if (confirmMsg) {
		Ext.MessageBox.confirm('提示', confirmMsg, function(btn) {
					if (btn == 'yes') {
						deleteAjax();
					}
				});
	} else {
		deleteAjax();
	}

}


function addLogout(){
Ext.util.Observable.observeClass(Ext.data.Connection);   
Ext.data.Connection.on('requestcomplete', function(conn, resp, options) {
	
	if (resp && resp.getResponseHeader && resp.getResponseHeader('__timeout')) {
		var form1 = new Ext.form.FormPanel({
					xtype : "formpanel",
					url : basepath+"../permission/LoginController/login.do",
					labelWidth : 95,
					labelAlign : "right",
					layout : "form",
					height : 142,
					buttonAlign : "center",
					items : [{
								name : "usercode",
								xtype : "textfield",
								fieldLabel : "用户名",
								allowBlank : false,
								anchor : "95%"
							}, {
								name : "password",
								xtype : "textfield",
								inputType : 'password',
								fieldLabel : "密码",
								allowBlank : false,
								anchor : "95%"
							}]
				});

		Ext.useShims = true;
		var windowm = new Ext.Window({
			title : "用户连接失效请重新登录",
			closable : false,
			width : 310,
			height : 139,
			buttonAlign : "center",
			layout : "fit",
			modal : true,
			plain : true,
			items : [form1],
			buttons : [{
				text : '提交',
				handler : function() {
					if (form1.getForm().isValid()) {
						idoLogout = false;
						form1.getForm().el.dom.action =  basepath+"../sysControl/permission/LoginController/login.do";
						form1.getForm().el.dom.submit();
					}
				}
			}, {
				text : '重置',
				handler : function() {
					form1.getForm().reset();
				}
			}]
		});
		windowm.show();

	} 
});
}